package com.example.pharmacypick.controller;

import com.example.pharmacypick.pojo.Prescription;
import com.example.pharmacypick.service.PrescriptionService;
import com.example.pharmacypick.utils.RespBean;
import com.example.pharmacypick.vo.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;

@RestController
@RequestMapping("/prescription")
@Slf4j
public class PrescriptionController {

    @Autowired
    PrescriptionService prescriptionService;

    @GetMapping
    public RespBean findPrescriptionByPatientRecord(@RequestParam int patientRecord){
        try {
            PageInfo<Prescription> allPrescriptions = prescriptionService.findPrescriptionByPatientRecord(patientRecord);
            return RespBean.success("成功",allPrescriptions);
        }catch (Exception e){
            e.printStackTrace();
            return RespBean.error("error");
        }
    }

    //新增或更新
    @PostMapping
    public RespBean save(@RequestBody Prescription prescription){
        log.info("处方数据:{}",prescription);

        return RespBean.success(prescription);
    }

}
